<?php

class Application_Model_DbTable_Customer extends Zend_Db_Table_Abstract
{
	protected $_name = 'tbl_customer';
	
	public function getFormCustomerData() {
		$result = $this->getAdapter()->fetchPairs('SELECT partyNumber, CONCAT(customerName, \' (\', customerNumber, \')\') AS customerName  FROM tbl_customer ORDER BY customerName ASC');
	
		return $result;
	}
	
	public function getFormSingleCustomer($partyNumber) {
		$result = $this->getAdapter()->fetchPairs('SELECT partyNumber, CONCAT(customerName, \' (\', customerNumber, \')\') AS customerName  FROM tbl_customer WHERE partyNumber='.$partyNumber.' ORDER BY customerName ASC');
	
		return $result;
	}
	
	
	public function getCustomerBySalesrep($salesrepId)
	{
		$result = $this->getAdapter()->fetchPairs('Select c.customerNumber, c.customerName FROM tbl_customer AS c, tbl_customer_salesrep AS cs, tbl_salesrep AS s WHERE c.partyNumber=cs.customer_partyNumber AND cs.salesrep_id=s.id AND s.id=\''.$salesrepId.'\'');
		return $result;
	}
	
}
